//
//  AppointmentManager.m
//  iModern
//
//  Created by Ralf on 5/13/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

#import "AppointmentManager.h"
#import "UMSocial.h"
#import "UMessage.h"

@implementation AppointmentManager

- (ResultSet *)queryAppointmentByType:(NSString *)type max:(NSInteger)max offset:(NSInteger)offset reviewed:(BOOL)reviewed
{
    NSDictionary *params = [NSMutableDictionary new];

    [params setValue:[self getSessionID] forKey:@"sessionID"];
    [params setValue:type forKey:@"type"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) reviewed] forKey:@"reviewed"];

    return [self request:@"article/queryAppointment" params:params];
}

- (ResultSet *)confirmAppointment:(NSString *)appointmentID
{
    NSDictionary *params = [NSMutableDictionary new];

    [params setValue:[self getSessionID] forKey:@"sessionID"];
    [params setValue:appointmentID forKey:@"appointmentID"];

    return [self request:@"article/confirmAppointment" params:params];
}

- (ResultSet *)reviewAppointment:(NSString *)appointmentID score:(NSString *)score review:(NSString *)review
{
    NSDictionary *params = [NSMutableDictionary new];

    [params setValue:[self getSessionID] forKey:@"sessionID"];
    [params setValue:appointmentID forKey:@"appointmentID"];
    [params setValue:score forKey:@"score"];
    [params setValue:review forKey:@"review"];

    return [self request:@"article/reviewAppointment" params:params];
}

- (ResultSet *)queryReviewAppointment:(NSString *)advertisingID max:(NSInteger )max offset:(NSInteger )offset
{
    NSDictionary *params = [NSMutableDictionary new];
    
    [params setValue:advertisingID forKey:@"advertisingID"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) max] forKey:@"max"];
    [params setValue:[[NSString alloc] initWithFormat:@"%ld", (long) offset] forKey:@"offset"];
    return [self request:@"article/queryReviewAppointment" params:params];
}

- (ResultSet *)cancelAppointment:(NSString *)appointmentID
{
    NSDictionary *params = [NSMutableDictionary new];

    [params setValue:[self getSessionID] forKey:@"sessionID"];
    [params setValue:appointmentID forKey:@"appointmentID"];

    return [self request:@"article/cancelAppointment" params:params];
}

- (ResultSet *)completeAppointment:(NSString *)appointmentID
{
    NSDictionary *params = [NSMutableDictionary new];

    [params setValue:[self getSessionID] forKey:@"sessionID"];
    [params setValue:appointmentID forKey:@"appointmentID"];

    return [self request:@"article/completeAppointment" params:params];
}

- (ResultSet *)createAppointment:(NSDictionary *)appointment
{
    NSMutableDictionary *params = [NSMutableDictionary new];

    //    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    //    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //    params[@"startTime"]       = [formatter stringFromDate:appointment[@"startTime"]];

    params[@"userName"]             = appointment[@"userName"];
    params[@"advertisingId"]        = appointment[@"advertisingId"];
    params[@"nameOfConsignee"]      = appointment[@"nameOfConsignee"];
    params[@"cellphoneOfConsignee"] = appointment[@"cellphoneOfConsignee"];
    params[@"quantity"]             = appointment[@"quantity"];
    params[@"address"]              = appointment[@"address"];
    params[@"message"]              = appointment[@"message"];
    params[@"price"]                = appointment[@"price"];
    params[@"message"]              = appointment[@"message"];
    params[@"sessionID"]            = [self getSessionID];
    params[@"umappkey"]             = [UMSocialData appKey];
    params[@"umappMasterSecret"]    = @"e8asdhlwx2ddq9dxlenrhqccvvgqrmow";

    return [self requestJSON:@"article/createAppointment" params:params];
}

@end
